package com.ohxwj.modules.web.controller;

import com.ohxwj.common.annotation.SysLog;
import com.ohxwj.common.utils.R;
import com.ohxwj.modules.web.entity.WebBannerEntity;
import com.ohxwj.modules.web.entity.WebMenuEntity;
import com.ohxwj.modules.web.service.WebBannerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Administrator on 2018-04-09.
 */
@RestController
@RequestMapping("/web/banner")
public class WebBannerController extends AbstractAction {

    @Autowired
    private WebBannerService webBannerService;

    @RequestMapping("/list")
    public R list() {
        List<WebBannerEntity> webBannerEntities = webBannerService.queryBanners();
        return R.ok().put("data", webBannerEntities);
    }

    @SysLog("add banner")
    @RequestMapping("/add")
    @RequiresPermissions("web:banner:save")
    public R add(@RequestBody WebBannerEntity webBannerEntity) {
        webBannerService.insertWebBanner(webBannerEntity);

        return R.ok();
    }

    @SysLog("update banner")
    @RequestMapping("/update")
    @RequiresPermissions("web:banner:update")
    public R update(@RequestBody WebBannerEntity webBannerEntity) {
        webBannerService.updateWebBanner(webBannerEntity);

        return R.ok();
    }

    @SysLog("delete banner")
    @RequestMapping("/delete")
    @RequiresPermissions("web:banner:delete")
    public R delete(int id) {
        webBannerService.deleteWebBanner(id);

        return R.ok();
    }

}
